package com.example.campusforumapi.controller;

import lombok.NoArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

public class BaseController {
//    解决后端请求时出现的CORS（跨源资源共享）问题
    @Configuration
    public class WebConfig implements WebMvcConfigurer {
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**")
                    .allowedOrigins("*") // 允许所有源
                    .allowedMethods("GET", "POST", "PUT", "DELETE");
        }
    }
}
